clear all
set mem 50m
set more off

use "/Users/gwf25/Dropbox/research/religion/final code/religion_all.dta"

//  Begin definition of variables

***Drop subjects who thought the experiment was about religion
gen id = _n
drop if id == 98 | id == 176 | id == 194 | id == 383

***Drop subjects who incorrectly completed the priming task. This includes subjects who leave more than half the responses blank. The following subjects
***all left at least questions #2-#7 blank in the sentence unscrambling task. 
drop if id==7 | id==719 | id==740 | id==762 | id==940

***An error led to some subjects seeing both the control and religion salient sentence unscrambling tasks. Here, we drop those subjects.
drop if prime_diff == 1

***"skipped" is a dummy variable for whether subjects skip the question that asks their religion. If they skip this question, we drop them from the sample 
***and if not, we assign a dummy variable to indicate the treatment group (religion salient or control) that subject belongs to.
gen skipped=0
replace skipped=1 if  s10q15==""
gen treatR=.
replace treatR=religion if skipped==0
drop if skipped==1

***Define religion
gen relig=.

***Note: 1 = protestant or other christian, 2 = catholic, 3 = jewish, 4 = agnostic/atheist
replace relig=1 if (s10q15=="Christian - Other (please specify below)" | s10q15=="Christian - Protestant (please specify denomination below)")
replace relig=2 if s10q15=="Christian - Catholic"
replace relig=3 if s10q15=="Jewish (Orthodox/Reformed/etc.)" | s10q15=="Jewish (Orthodox/Reform/etc.)"
replace relig=4 if (s10q15=="Agnostic" | s10q15=="Atheist")

***Drop Mormon/Othodox Christians from the sample
drop if s10q15sp == "Greek Orthodox"
drop if s10q15sp == "Russian Othrodox"
drop if s10q15sp == "greek orthodox"
drop if s10q15sp == "Orthodox Christian"
drop if s10q15sp == "Greek Orthdox"
drop if s10q15sp == "christian orthodox"
drop if s10q15sp == "Greek Orthodox Christian"
drop if s10q15sp == "Russian orthodox"
drop if s10q15sp == "Church of Jesus Christ of Latter Day Saints"
drop if s10q15sp == "Greek Orthodox"

drop id
// End of variables


***Create the divine punishment variable
gen divinepunish = s10q18sp4
egen divinepunish_std1 = std(divinepunish) if relig == 1
egen divinepunish_std2 = std(divinepunish) if relig == 2
egen divinepunish_std3 = std(divinepunish) if relig == 3
egen divinepunish_std4 = std(divinepunish) if relig == 4
gen divinepunish_std1_R = divinepunish_std1 * treatR if relig == 1
gen divinepunish_std2_R = divinepunish_std2 * treatR if relig == 2
gen divinepunish_std3_R = divinepunish_std3 * treatR if relig == 3
gen divinepunish_std4_R = divinepunish_std4 * treatR if relig == 4

***Create the median religious service attendance variable
gen religserv_freq = .
replace religserv_freq = 1 if s10q16 == "Never"
replace religserv_freq = 2 if s10q16 == "Less than once a month"
replace religserv_freq = 3 if s10q16 == "Once a month"
replace religserv_freq = 4 if s10q16 == "A few times a month"
replace religserv_freq = 5 if s10q16 == "Once a week"
replace religserv_freq = 6 if s10q16 == "A few times a week"
replace religserv_freq = 7 if s10q16 == "Once a day"
replace religserv_freq = 8 if s10q16 == "More than once a day"

egen median1 = median(religserv_freq) if relig == 1
gen religserv_freq1_median = .
replace religserv_freq1_median = 1 if religserv_freq > median1
replace religserv_freq1_median = 0 if religserv_freq <= median1

egen median2 = median(religserv_freq) if relig == 2
gen religserv_freq2_median = .
replace religserv_freq2_median = 1 if religserv_freq > median2
replace religserv_freq2_median = 0 if religserv_freq <= median2

egen median3 = median(religserv_freq) if relig == 3
gen religserv_freq3_median = .
replace religserv_freq3_median = 1 if religserv_freq > median3
replace religserv_freq3_median = 0 if religserv_freq <= median3

egen median4 = median(religserv_freq) if relig == 4
gen religserv_freq4_median = .
replace religserv_freq4_median = 1 if religserv_freq > median4
replace religserv_freq4_median = 0 if religserv_freq <= median4

gen religserv_freq1_median_R = treatR * religserv_freq1_median if relig == 1
gen religserv_freq2_median_R = treatR * religserv_freq2_median if relig == 2
gen religserv_freq3_median_R = treatR * religserv_freq3_median if relig == 3
gen religserv_freq4_median_R = treatR * religserv_freq4_median if relig == 4

*Jewish Gift-Exchange Reciprocity
rename m wageoffer

***Create the cost, cXXX, for providing a certain amount of effort at eXXX. A certain monetary cost is associated with each level of output. So, we have:
***[eXXX, cXXX] = [(1,$0.00),(2,$0.04),(3,$0.08),(4,$0.16),(5,$0.24),(6,$0.32),(7,$0.40),(8,$0.48),(9,$0.60),(10,$0.72)]
gen c000 = .
replace c000 = 0 if e000 == 1
replace c000 = .04 if e000 == 2
replace c000 = .08 if e000 == 3
replace c000 = .16 if e000 == 4
replace c000 = .24 if e000 == 5
replace c000 = .32 if e000 == 6
replace c000 = .40 if e000 == 7
replace c000 = .48 if e000 == 8
replace c000 = .60 if e000 == 9
replace c000 = .72 if e000 == 10

gen c050 = .
replace c050 = 0 if e050 == 1
replace c050 = .04 if e050 == 2
replace c050 = .08 if e050 == 3
replace c050 = .16 if e050 == 4
replace c050 = .24 if e050 == 5
replace c050 = .32 if e050 == 6
replace c050 = .40 if e050 == 7
replace c050 = .48 if e050 == 8
replace c050 = .60 if e050 == 9
replace c050 = .72 if e050 == 10

gen c100 = .
replace c100 = 0 if e100 == 1
replace c100 = .04 if e100 == 2
replace c100 = .08 if e100 == 3
replace c100 = .16 if e100 == 4
replace c100 = .24 if e100 == 5
replace c100 = .32 if e100 == 6
replace c100 = .40 if e100 == 7
replace c100 = .48 if e100 == 8
replace c100 = .60 if e100 == 9
replace c100 = .72 if e100 == 10

gen c150 = .
replace c150 = 0 if e150 == 1
replace c150 = .04 if e150 == 2
replace c150 = .08 if e150 == 3
replace c150 = .16 if e150 == 4
replace c150 = .24 if e150 == 5
replace c150 = .32 if e150 == 6
replace c150 = .40 if e150 == 7
replace c150 = .48 if e150 == 8
replace c150 = .60 if e150 == 9
replace c150 = .72 if e150 == 10

gen c200 = .
replace c200 = 0 if e200 == 1
replace c200 = .04 if e200 == 2
replace c200 = .08 if e200 == 3
replace c200 = .16 if e200 == 4
replace c200 = .24 if e200 == 5
replace c200 = .32 if e200 == 6
replace c200 = .40 if e200 == 7
replace c200 = .48 if e200 == 8
replace c200 = .60 if e200 == 9
replace c200 = .72 if e200 == 10

gen c250 = .
replace c250 = 0 if e250 == 1
replace c250 = .04 if e250 == 2
replace c250 = .08 if e250 == 3
replace c250 = .16 if e250 == 4
replace c250 = .24 if e250 == 5
replace c250 = .32 if e250 == 6
replace c250 = .40 if e250 == 7
replace c250 = .48 if e250 == 8
replace c250 = .60 if e250 == 9
replace c250 = .72 if e250 == 10

gen c300 = .
replace c300 = 0 if e300 == 1
replace c300 = .04 if e300 == 2
replace c300 = .08 if e300 == 3
replace c300 = .16 if e300 == 4
replace c300 = .24 if e300 == 5
replace c300 = .32 if e300 == 6
replace c300 = .40 if e300 == 7
replace c300 = .48 if e300 == 8
replace c300 = .60 if e300 == 9
replace c300 = .72 if e300 == 10

gen c350 = .
replace c350 = 0 if e350 == 1
replace c350 = .04 if e350 == 2
replace c350 = .08 if e350 == 3
replace c350 = .16 if e350 == 4
replace c350 = .24 if e350 == 5
replace c350 = .32 if e350 == 6
replace c350 = .40 if e350 == 7
replace c350 = .48 if e350 == 8
replace c350 = .60 if e350 == 9
replace c350 = .72 if e350 == 10

gen c400 = .
replace c400 = 0 if e400 == 1
replace c400 = .04 if e400 == 2
replace c400 = .08 if e400 == 3
replace c400 = .16 if e400 == 4
replace c400 = .24 if e400 == 5
replace c400 = .32 if e400 == 6
replace c400 = .40 if e400 == 7
replace c400 = .48 if e400 == 8
replace c400 = .60 if e400 == 9
replace c400 = .72 if e400 == 10

***Drop the highest effort amount
drop c400

***In order to properly reshape the data, we must rename the effort and cost of effort at $0 and $0.50
rename e000 e0
rename e050 e50
rename c000 c0
rename c050 c50

***Create the corresponding wages for each effort choice
gen w0 = 0
gen w50 = .5
gen w100 = 1
gen w150 = 1.5
gen w200 = 2
gen w250 = 2.5
gen w300 = 3
gen w350 = 3.5

***Create the estimated regression parameter where beta=reciprocity
gen beta=.

gen id = _n

***Reshape the data so that we can regress cost of effort on all possible wages, by subject
reshape long c, i(id) j(w)

***Loop through all subjects and regress the effort on wage by each subject and save values of regression
***Note that some subjects did not do this section so we exclude them here. Only subjects numbered 263 through 689 did the gift exchange task.
quiet forvalues x = 263/689 {
reg c w if id ==`x'
replace beta=_b[w] if id ==`x'
}

***Reshape the data to its original form
reshape wide c, i(id) j(w)

reg beta treatR divinepunish_std3_R divinepunish_std3 if relig == 3, r
reg beta treatR religserv_freq3_median_R religserv_freq3_median if relig == 3, r

*Atheist/Agnostic Risk Premium
clear all
set mem 50m
set more off

use "/Users/gwf25/Dropbox/research/religion/final code/religion_all.dta"

//  Begin definition of variables

***Drop subjects who thought the experiment was about religion
gen id = _n
drop if id == 98 | id == 176 | id == 194 | id == 383

***Drop subjects who incorrectly completed the priming task. This includes subjects who leave more than half the responses blank. The following subjects
***all left at least questions #2-#7 blank in the sentence unscrambling task. 
drop if id==7 | id==719 | id==740 | id==762 | id==940

***An error led to some subjects seeing both the control and religion salient sentence unscrambling tasks. Here, we drop those subjects.
drop if prime_diff == 1

***"skipped" is a dummy variable for whether subjects skip the question that asks their religion. If they skip this question, we drop them from the sample 
***and if not, we assign a dummy variable to indicate the treatment group (religion salient or control) that subject belongs to.
gen skipped=0
replace skipped=1 if  s10q15==""
gen treatR=.
replace treatR=religion if skipped==0
drop if skipped==1

***Define religion
gen relig=.

***Note: 1 = protestant or other christian, 2 = catholic, 3 = jewish, 4 = agnostic/atheist
replace relig=1 if (s10q15=="Christian - Other (please specify below)" | s10q15=="Christian - Protestant (please specify denomination below)")
replace relig=2 if s10q15=="Christian - Catholic"
replace relig=3 if s10q15=="Jewish (Orthodox/Reformed/etc.)" | s10q15=="Jewish (Orthodox/Reform/etc.)"
replace relig=4 if (s10q15=="Agnostic" | s10q15=="Atheist")

***Drop Mormon/Othodox Christians from the sample
drop if s10q15sp == "Greek Orthodox"
drop if s10q15sp == "Russian Othrodox"
drop if s10q15sp == "greek orthodox"
drop if s10q15sp == "Orthodox Christian"
drop if s10q15sp == "Greek Orthdox"
drop if s10q15sp == "christian orthodox"
drop if s10q15sp == "Greek Orthodox Christian"
drop if s10q15sp == "Russian orthodox"
drop if s10q15sp == "Church of Jesus Christ of Latter Day Saints"
drop if s10q15sp == "Greek Orthodox"


// End of variables


***Create the divine punishment variable
gen divinepunish = s10q18sp4
egen divinepunish_std1 = std(divinepunish) if relig == 1
egen divinepunish_std2 = std(divinepunish) if relig == 2
egen divinepunish_std3 = std(divinepunish) if relig == 3
egen divinepunish_std4 = std(divinepunish) if relig == 4
gen divinepunish_std1_R = divinepunish_std1 * treatR if relig == 1
gen divinepunish_std2_R = divinepunish_std2 * treatR if relig == 2
gen divinepunish_std3_R = divinepunish_std3 * treatR if relig == 3
gen divinepunish_std4_R = divinepunish_std4 * treatR if relig == 4

***Create the median religious service attendance variable
gen religserv_freq = .
replace religserv_freq = 1 if s10q16 == "Never"
replace religserv_freq = 2 if s10q16 == "Less than once a month"
replace religserv_freq = 3 if s10q16 == "Once a month"
replace religserv_freq = 4 if s10q16 == "A few times a month"
replace religserv_freq = 5 if s10q16 == "Once a week"
replace religserv_freq = 6 if s10q16 == "A few times a week"
replace religserv_freq = 7 if s10q16 == "Once a day"
replace religserv_freq = 8 if s10q16 == "More than once a day"

egen median1 = median(religserv_freq) if relig == 1
gen religserv_freq1_median = .
replace religserv_freq1_median = 1 if religserv_freq > median1
replace religserv_freq1_median = 0 if religserv_freq <= median1

egen median2 = median(religserv_freq) if relig == 2
gen religserv_freq2_median = .
replace religserv_freq2_median = 1 if religserv_freq > median2
replace religserv_freq2_median = 0 if religserv_freq <= median2

egen median3 = median(religserv_freq) if relig == 3
gen religserv_freq3_median = .
replace religserv_freq3_median = 1 if religserv_freq > median3
replace religserv_freq3_median = 0 if religserv_freq <= median3

egen median4 = median(religserv_freq) if relig == 4
gen religserv_freq4_median = .
replace religserv_freq4_median = 1 if religserv_freq > median4
replace religserv_freq4_median = 0 if religserv_freq <= median4

gen religserv_freq1_median_R = treatR * religserv_freq1_median if relig == 1
gen religserv_freq2_median_R = treatR * religserv_freq2_median if relig == 2
gen religserv_freq3_median_R = treatR * religserv_freq3_median if relig == 3
gen religserv_freq4_median_R = treatR * religserv_freq4_median if relig == 4


***Drop those subjects who don't take part in the risk preference section
drop if s3q1 == .

***Generate upper limit for risk with small amounts
gen risk1=.
replace risk1=(1.6*0.5-1) if s3q1==1
gen risk2=.
replace risk2=(2*0.5-1) if s3q2==1
gen risk3=.
replace risk3=(2.4*0.5-1) if s3q3==1
gen risk4=.
replace risk4=(2.8*0.5-1) if s3q4==1
gen risk5=.
replace risk5=(3.2*0.5-1) if s3q5==1
gen risk6=.
replace risk6=(3.6*0.5-1) if s3q6==1

***Choose the upper limit for the first time a subject chooses the risky asset with small amounts.
gen reservationrisk1= min(risk1,risk2,risk3,risk4,risk5,risk6)

***Generate upper limit for risk with large amounts
gen risk7=.
replace risk7=(160*0.5-100)/100 if s4q1==1
gen risk8=.
replace risk8=(200*0.5-100)/100 if s4q2==1
gen risk9=.
replace risk9=(240*0.5-100)/100 if s4q3==1
gen risk10=.
replace risk10=(280*0.5-100)/100 if s4q4==1
gen risk11=.
replace risk11=(320*0.5-100)/100 if s4q5==1
gen risk12=.
replace risk12=(360*0.5-100)/100 if s4q6==1

***Choose the upper limit for the first time a subject chooses the risky asset with large amounts.
gen reservationrisk2= min(risk7,risk8,risk9,risk10,risk11,risk12)

***Create two entries per subject. One is for small amounts and the other is for large amounts. riskchoice indicates whether it is a small or large stake gamble. 
reshape long reservationrisk, i(id) j(riskchoice)

***largestake is a dummy where a 1 indicates risk choices with large amounts and a 0 indicates risk choices with small amounts.
gen largestake=0
replace largestake= 1 if riskchoice==2 

***Recall reservationrisk indicates the upper limit. Rename this variable risku and create another variable, riskl, which will indicate the lower limit.
rename reservationrisk risk
gen riskl=.
gen risku=risk

***Fill in values for the lower limit.
***Note that even if someone always chose the safe option, they are assigned a missing value for the upper limit and the highest possible value we ask about for the lower limit. So they are properly taken care of.
replace riskl=. if risk < -.2
replace riskl=(1.6*0.5-1) if risk == 0
replace riskl=(2*0.5-1) if risk > .1 & risk < .3
replace riskl=(2.4*0.5-1) if risk > .3 & risk < .5
replace riskl=(2.8*0.5-1) if risk > .5 & risk < .7
replace riskl=(3.2*0.5-1) if risk > .7 & risk < .9
replace riskl=(3.6*0.5-1) if risk == . & s4q1 ~= .

intreg riskl risku treatR divinepunish_std4_R divinepunish_std4 largestake if relig==4, cluster(id)
intreg riskl risku treatR religserv_freq4_median_R religserv_freq4_median largestake if relig==4, cluster(id)
